import axios from 'axios';

const api = axios.create({
  baseURL: 'http://localhost:7001',
  timeout: 5000,
  headers: {
    'Authorization': 'token',
  },
});

const getTags = '/api/tags'
const getArticles = '/api/articles'
const login = '/api/users/login'
const register = '/api/users'
const getCurrentUser = '/api/user'
const updateUser = '/api/user'
const createArticle = '/api/articles'
const updateArticle = '/api/articles/:slug'
const getArticle = '/api/articles/:slug'
const getComments = '/api/articles/:slug/comments'

const favoriteArticle = '/api/articles/:slug/favorite'
const unfavoriteArticle = '/api/articles/:slug/favorite'
const deleteComment = '/api/articles/:slug/comments/:id'
const addComments = '/api/articles/:slug/comments'
const deleteArticle = '/api/articles/:slug'
const feedArticles = '/api/articles/feed'
const followUser = '/api/profiles/:username/follow'
const unfollowUser = '/api/profiles/:username/follow'
const getProfile = '/api/profiles/'


export default {
  axios: api,
  url: {
    getProfile,
    unfollowUser,
    followUser,
    feedArticles,
    addComments,
    deleteComment,
    deleteArticle,
    unfavoriteArticle,
    favoriteArticle,
    getComments,
    getArticle,
    updateArticle,
    createArticle,
    updateUser,
    getCurrentUser,
    getTags,
    getArticles,
    login,
    register,
  },
  setToken(token) {
    api.defaults.headers.common['Authorization'] = `${token}`;
  }
};